package com.hr.剑指offer.work1;

/**
 * @author 周恒哲
 * @date 2020/06/16
 **/
public class 面试题16_数值的整数次方 {
    public static double myPow(double x, int n) {
        if (x == 0) {
            return 0;
        }
        long b = n;
        double res = 1.0;
        if (b < 0) {
            x = 1 / x;
            b = -b;
        }
        while (b > 0) {
            if ((b & 1) == 1) {
                res*=x;
            }
            x*=x;
            b>>=1;
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(面试题16_数值的整数次方.myPow(2.00000, -2));
    }
}
